<template>
<el-dialog
    :title="$t('plus.add_activity')"
    v-model="dialogVisible"
    @close="dialogFormVisible"
    :close-on-click-modal="false"
    :close-on-press-escape="false"
    width="600px"
  >
    <el-form size="small" :model="form" ref="form">
      <el-form-item
        :label="$t('plus.activity_name')"
        :label-width="formLabelWidth"
        prop="activeName"
        :rules="[{  required: true,  message: ' '}]"
      >
        <el-input
          v-model="form.activeName"
          :placeholder="$t('plus.input_activity_name')"
        ></el-input>
      </el-form-item>
      <el-form-item :label="$t('plus.threshold_type')" :label-width="formLabelWidth">
        <div>
          <el-radio v-model="form.fullType" :label="1">{{$t('plus.threshold_amount')}}</el-radio>
          <el-radio v-model="form.fullType" :label="2">{{$t('plus.threshold_quantity')}}</el-radio>
        </div>
      </el-form-item>
      <el-form-item
        :label="$t('plus.threshold_value')"
        :label-width="formLabelWidth"
        prop="fullValue"
        :rules="[{  required: true,  message: ' '}]"
      >
        <el-input
          type="number"
          :precision="1"
          :step="1"
          :min="0"
          :placeholder="$t('plus.input_threshold_value')"
          v-model="form.fullValue"
        ></el-input>
      </el-form-item>
      <el-form-item :label="$t('plus.discount_type')" :label-width="formLabelWidth">
        <div>
          <el-radio v-model="form.reduceType" :label="1">{{$t('plus.discount_amount')}}</el-radio>
          <el-radio v-model="form.reduceType" :label="2">{{$t('plus.discount_percent')}}</el-radio>
        </div>
      </el-form-item>
      <el-form-item
        :label="$t('plus.discount_value')"
        :label-width="formLabelWidth"
        prop="reduceValue"
        :rules="[{  required: true,  message: ' '}]"
      >
        <el-input
          type="number"
          :precision="1"
          :step="1"
          :min="0"
          :placeholder="$t('plus.input_threshold_value')"
          v-model="form.reduceValue"
        ></el-input>
        <div class="tips"> {{$t('plus.discount_note')}} 

</div>
      </el-form-item>
    </el-form>
    <template #footer>
      <div class="dialog-footer">
        <el-button @click="dialogFormVisible">{{$t('plus.cancel')}}</el-button>
        <el-button type="primary" @click="add()" :disabled="submit_loading"
          >{{$t('plus.confirm')}}</el-button
        >
      </div>
    </template>
  </el-dialog>
</template>

<script>
import FullreduceApi from "@/api/plus/fullreduce.js";
export default {
  data() {
    return {
      form: {
        /*活动名称*/
        activeName: "",
        /*满类型*/
        fullType: 1,
        /*满值*/
        fullValue: 0,
        /*减类型*/
        reduceType: 1,
        /*减值*/
        reduceValue: 0
      },
      /*左边长度*/
      formLabelWidth: "120px",
      /*是否显示*/
      dialogVisible: false,
      /*是否正在提交*/
      submit_loading: false
    };
  },
  props: ["open_add"],
  created() {
    this.dialogVisible = this.open_add;
  },
  methods: {
    /*添加等级*/
    add() {
      let self = this;
      let params = this.form;
      self.$refs.form.validate(valid => {
        if (valid) {
          self.submit_loading = true;
          FullreduceApi.add(params, true).then(data => {
            self.submit_loading = false;
            ElMessage({
              message: data.msg,
              type: "success"
            });
            self.dialogFormVisible(true);
          }).catch(error => {
            self.submit_loading = false;
          });
        }
      });
    },
    /*关闭弹窗*/
    dialogFormVisible(e) {
      if (e) {
        this.$emit("closeDialog", {
          type: "success",
          openDialog: false
        });
      } else {
        this.$emit("closeDialog", {
          type: "error",
          openDialog: false
        });
      }
    }
  }
};
</script>

